﻿using System;
using System.Collections.Generic;
using System.Collections;
using Iesi.Collections.Generic;

namespace Bunian.Core.BusinessObjects
{
    public enum Kinship
    {
         Father
        ,Mother
        ,UncleFatherSide
        ,AuntFatherSide
        ,GrandfatherFatherSide
        ,GrandmotherFatherSide
        ,UncleMotherSide
        ,AuntMotherSide
        ,GrandfatherMotherSide
        ,GrandmotherMotherSide
        ,Other
    }

    public class Family : IBeneficiary
    {
        #region Private Fields

        private decimal _baseIncome;
        private long _beneficiaryId;
        private IList<Tender> _beneficiaryTenders;
        
        private Contact _father;
        private Contact _mother;
        private Contact _provider;
        private Kinship _providerKinship;
        private Contact _contactDetails;
        private string _description;

        private IList<Child> _familyMembers;

        #endregion

        #region Public Properties

        public virtual long Id
        {
            get
            {
                return _beneficiaryId;
            }
            set
            {
                _beneficiaryId = value;
            }
        }

        public virtual IList<Child> FamilyMembers
        {
            get
            {
                return _familyMembers;
            }
            set
            {
                _familyMembers = value;
            }
        }

        public virtual Contact Father
        {
            get
            {
                return _father;
            }
            set
            {
                _father = value;
            }
        }

        public virtual Contact Mother
        {
            get
            {
                return _mother;
            }
            set
            {
                _mother = value;
            }
        }

        public virtual Contact Provider
        {
            get
            {
                return _provider;
            }
            set
            {
                _provider = value;
            }
        }

        public virtual Kinship ProviderKinship
        {
            get
            {
                return _providerKinship;
            }
            set
            {
                _providerKinship = value;
            }
        }

        public virtual Contact ContactDetails
        {
            get
            {
                return _contactDetails;
            }
            set
            {
                _contactDetails = value;
            }
        }

        #endregion
         
        #region IBeneficiary Members

        public virtual decimal BaseIncome
        {
            get
            {
                return _baseIncome;
            }
            set
            {
                _baseIncome = value;
            }
        }

        public virtual string SourcesOfIncome { get; set; }
        
        public virtual decimal Deficiency
        {
            get
            {
                return 10;
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public virtual IList<Tender> BeneficiaryTenders
        {
            get
            {
                return _beneficiaryTenders;
            }
            set
            {
                _beneficiaryTenders = value;
            }
        }

        public virtual string Description
        {
            get
            {
                return _description;
            }
            set
            {
                _description = value;
            }
        }

        #endregion

        public virtual int GetCoveredCount()
        {
            int coveredChildren = 0;

            if (null != this.FamilyMembers)
            {
                foreach (Child chld in this.FamilyMembers)
                {
                    if (chld.IsTender<Orphan>())
                    {
                        Orphan currentOrphan = chld.GetTender<Orphan>();

                        if (currentOrphan.IsSponsored())
                        {
                            coveredChildren += 1;
                        }
                    }
                }
            }

            return coveredChildren;
        }
    }
}